package entities.controllers;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import entities.kinds.Cat;
import entities.pmf.PMF;

public class Cats {
	static final PersistenceManager pm = PMF.getInstance().getPersistenceManager();

	public static void add(String type) {
		try {
			Cat cat = new Cat();
			cat.setType(type);
			pm.makePersistent(cat);
		} catch (Exception e) {
			System.out.println("cat add err:" + e);
		}
	}

	public static String getCategories() {
		Query q = pm.newQuery(Cat.class);
		@SuppressWarnings("unchecked")
		List<Cat> res = (List<Cat>) q.execute();
		if (!res.isEmpty()) {
			String toRet = "null";
			for (Cat c : res) {
				toRet += ",\"" + c.getType() + "\"";
			}
			return toRet;
		}
		return "";

	}

}
